package ljl.alg.wangzheng_camp.round1.veryveryeasy;

public class _9_is_palindrome {
    
    /**
     * 搞成字符串，判断？
     * 我先用 long 试试吧，反过来
     *
     * 能过但不是特别快
     *
     * */
    public boolean isPalindrome44(int x) {
        if (x < 0) return false;
        long reverse = 0;
        int t = x;
        while (t > 0) {
            reverse = reverse * 10 + t % 10;
            t /= 10;
        }
        return reverse == x;
    }
    
    /**
     *
     * 骚套路，翻转一半数字
     * */
    public boolean isPalindrome(int x) {
        if (x < 0 || x % 10 == 0 && x != 0) return false;
        long reverse = 0;
        /*
        * 没想到还有悬念……
        * 这个等号是取不到的
        *
        * x 要比 reverse 大，退出条件才是 x <= reverse
        * */
        while (x > reverse) {
            reverse = reverse * 10 + x % 10;
            x /= 10;
        }
        return reverse == x || reverse / 10 == x;
    }
}
